package com.xiaoshu.controller;

import com.xiaoshu.service.DoubleWriteRedisTemplate;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * code is far away from bug with the animal protecting
 * ┏┓　　　┏┓
 * ┏┛┻━━━┛┻┓
 * ┃　　　　　　　┃
 * ┃　　　━　　　┃
 * ┃　┳┛　┗┳　┃
 * ┃　　　　　　　┃
 * ┃　　　┻　　　┃
 * ┃　　　　　　　┃
 * ┗━┓　　　┏━┛
 * 　　┃　　　┃神兽保佑
 * 　　┃　　　┃代码无BUG！
 * 　　┃　　　┗━━━┓
 * 　　┃　　　　　　　┣┓
 * 　　┃　　　　　　　┏┛
 * 　　┗┓┓┏━┳┓┏┛
 * 　　　┃┫┫　┃┫┫
 * 　　　┗┻┛　┗┻┛
 *
 * @Description : function description
 * ---------------------------------
 * @Author : deane
 * @Date : Create in 2021/3/20 8:59
 * <p>
 * Copyright (C)2013-2021 小树盛凯科技 All rights reserved.
 */

@RestController
@RequestMapping(value = "/redis")
@Slf4j
public class RedisTemplateController {

    private DoubleWriteRedisTemplate doubleWriteRedisTemplate;

    @Autowired
    @Qualifier(value = "masterDoubleWriteRedisTemplate")
    public void setDoubleWriteRedisTemplate(DoubleWriteRedisTemplate doubleWriteRedisTemplate) {
        this.doubleWriteRedisTemplate = doubleWriteRedisTemplate;
    }

    @GetMapping(value = "/getString")
    public String getString(@RequestParam(value = "key") String key){
        log.info("[RedisTemplateController] start get Key :{}", key );
        doubleWriteRedisTemplate.getString(key);
        return "Hello getString " + key;
    }

    @GetMapping(value = "/setString")
    public String setString(@RequestParam(value = "key") String key){
        log.info("[RedisTemplateController] start set Key :{}", key );
        doubleWriteRedisTemplate.setString(key, "deane");
        return "Hello setString" + key;
    }
}
